class RegistroDeAvaliacaoController {
    
    def index = { redirect(action:avaliar,params:params) }

    // the delete, save and update actions only accept POST requests
    def allowedMethods = [delete:'POST', save:'POST', update:'POST']

    def list = {
        if(!params.max) params.max = 10
        [ registroDeAvaliacaoList: RegistroDeAvaliacao.list( params ) ]
    }

    def show = {
        def registroDeAvaliacao = RegistroDeAvaliacao.get( params.id )

        if(!registroDeAvaliacao) {
            flash.message = "RegistroDeAvaliacao not found with id ${params.id}"
            redirect(action:list)
        }
        else { return [ registroDeAvaliacao : registroDeAvaliacao ] }
    }

    def delete = {
        def registroDeAvaliacao = RegistroDeAvaliacao.get( params.id )
        if(registroDeAvaliacao) {
            registroDeAvaliacao.delete()
            flash.message = "RegistroDeAvaliacao ${params.id} deleted"
            redirect(action:list)
        }
        else {
            flash.message = "RegistroDeAvaliacao not found with id ${params.id}"
            redirect(action:list)
        }
    }

    def edit = {
        def registroDeAvaliacao = RegistroDeAvaliacao.get( params.id )

        if(!registroDeAvaliacao) {
            flash.message = "RegistroDeAvaliacao not found with id ${params.id}"
            redirect(action:list)
        }
        else {
            return [ registroDeAvaliacao : registroDeAvaliacao ]
        }
    }

    def update = {
        def registroDeAvaliacao = RegistroDeAvaliacao.get( params.id )
        if(registroDeAvaliacao) {
            registroDeAvaliacao.properties = params
            if(!registroDeAvaliacao.hasErrors() && registroDeAvaliacao.save()) {
                flash.message = "RegistroDeAvaliacao ${params.id} updated"
                redirect(action:show,id:registroDeAvaliacao.id)
            }
            else {
                render(view:'edit',model:[registroDeAvaliacao:registroDeAvaliacao])
            }
        }
        else {
            flash.message = "RegistroDeAvaliacao not found with id ${params.id}"
            redirect(action:edit,id:params.id)
        }
    }

    def create = {
        def registroDeAvaliacao = new RegistroDeAvaliacao()
        registroDeAvaliacao.properties = params
        return ['registroDeAvaliacao':registroDeAvaliacao]
    }

    def save = {
        def registroDeAvaliacao = new RegistroDeAvaliacao(params)
        if(!registroDeAvaliacao.hasErrors() && registroDeAvaliacao.save()) {
            flash.message = "RegistroDeAvaliacao ${registroDeAvaliacao.id} created"
            redirect(action:show,id:registroDeAvaliacao.id)
        }
        else {
            render(view:'create',model:[registroDeAvaliacao:registroDeAvaliacao])
        }
    }

    def avaliar = {
        if(!params.max) params.max = 10
        def avaliacao = Avaliacao.findById(1)
        def resposta = Resposta
        [ perguntaList: Pergunta.findAllByAvaliacao(avaliacao), avaliacao:avaliacao, resposta:resposta ]
    }

}
